const request = (url, data) => {
  return fetch(url, data)
    .then((response) => {
      return response.json()
    })
    .then((res) => {
      // if (res.retcode === -90001) {
      //   location.hash = 'login';
      //   location.reload();
      // }
      // else {
      //   return res;
      // }
      return res
    })
}

export default {
  post: (url, data) => {
    return request(url, {
      ...data,
      method: 'POST',
      credentials: 'include',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json; charset=UTF-8'
        // 'x-csrf-token': Cookies.get('csrfToken')
      }
    })
  },
  get: (url, data) => {
    return request(url, { ...data, method: 'GET', credentials: 'include' })
  }
}
